package com.hgk.wanwan.login.forgetPas;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.common.android.volley.VolleyError;
import com.common.dongqiuhui.apps.comm.constants.UrlConstans;
import com.common.dongqiuhui.apps.comm.model.BaseController;
import com.hgk.common.common.constants.DataConstants;
import com.hgk.common.common.ui.activity.SimpleBaseActivity;
import com.hgk.common.common.ui.view.RippleView;

import java.util.Map;

import width.hgk.wanwan.R;

public class PwdRetakeActivity extends SimpleBaseActivity {

    private final String EDIT_PASSWORD_URL = UrlConstans.ZWCOMMOMURL+"/domain/user/alt_password.json";
    private EditText mEtOnePwd,mEtTwoPwd;
    private RippleView mRipGone;
    private Button mBtnGone;
    private String mOnePwd,mTwoPwd;
    private String mCode,mPhoneNumber;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_pwd_retake);
        initView();
        mCode = getIntent().getStringExtra(DataConstants.TEL_CODE);
        mPhoneNumber = getIntent().getStringExtra(DataConstants.TEL_NUMBER);
    }

    private void initView() {
        mEtOnePwd = (EditText) findViewById(R.id.et_pwd_retake_one);
        mEtTwoPwd = (EditText) findViewById(R.id.et_pwd_retake_two);
        mRipGone = (RippleView) findViewById(R.id.rip_pwd_retake);
        mBtnGone = (Button) findViewById(R.id.btn_pwd_retake);
        mOnePwd = mEtOnePwd.getText().toString();
        mTwoPwd = mEtTwoPwd.getText().toString();

        mRipGone.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {
            @Override
            public void onComplete(RippleView rippleView) {
                if (!TextUtils.isEmpty(mOnePwd) && !TextUtils.isEmpty(mTwoPwd)) {
                    if (!mOnePwd.equals(mTwoPwd)) {
                        Toast.makeText(mContext, "两次密码不一致", Toast.LENGTH_SHORT).show();
                    } else {
                        getNetDataForPost("alt_pwd", EDIT_PASSWORD_URL, BaseController.class);
                    }
                } else {
                    Toast.makeText(mContext, "请输入两次相同密码", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    @Override
    protected Map getApiParams(String action) {
        return null;
    }

    @Override
    protected void success(String action, Object result) {

    }

    @Override
    protected void fail(String action, String errorStr) {

    }

    @Override
    protected void netfail(String action, VolleyError volleyError) {

    }

    @Override
    public void setLeftButton(RelativeLayout relativeLayout, Button button) {

    }

    @Override
    public void setRightButton(RelativeLayout relativeLayout, Button button) {

    }

    @Override
    public Object getTitleString() {
        return "找回密码";
    }

    @Override
    public int getBodyView() {
        return R.layout.activity_pwd_retake;
    }
    public static void launch(Context context,String code,String number){
        Intent intent = new Intent(context,PwdRetakeActivity.class);
        intent.putExtra(DataConstants.TEL_CODE,code);
        intent.putExtra(DataConstants.TEL_NUMBER,number);
        context.startActivity(intent);
    }
}
